﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// “用户控件”项模板在 http://go.microsoft.com/fwlink/?LinkId=234236 上提供

namespace Studio77.GuessTheWordsWin8.Views
{
    public sealed partial class VisualKeyboard : UserControl
    {
        static List<string> keys1 = new List<string>();
        static List<string> keys2 = new List<string>();
        static List<string> keys3 = new List<string>();
        const int columns = 8;
        const int rows = 3;

        public VisualKeyboard()
        {
            this.InitializeComponent();
            this.Loaded += VisualKeyboard_Loaded;
        }

        void VisualKeyboard_Loaded(object sender, RoutedEventArgs e)
        {
            this.Loaded -= VisualKeyboard_Loaded;
            this.cvsRoot.Children.Clear();
            keys1.Add("Q");
            keys1.Add("W");
            keys1.Add("E");
            keys1.Add("R");
            keys1.Add("T");
            keys1.Add("Y");
            keys1.Add("U");
            keys1.Add("I");
            keys1.Add("O");
            keys1.Add("P");
            keys2.Add("A");
            keys2.Add("S");
            keys2.Add("D");
            keys2.Add("F");
            keys2.Add("G");
            keys2.Add("H");
            keys2.Add("J");
            keys2.Add("K");
            keys2.Add("L");
            keys3.Add("Z");
            keys3.Add("X");
            keys3.Add("C");
            keys3.Add("V");
            keys3.Add("B");
            keys3.Add("N");
            keys3.Add("M");

            int itemWidth = 67;
            int itemHeight = 87;

            //第1行
            for (int i = 0; i < 10; i++)
            {
                double left = itemWidth * i;
                double top = 0;

                String keyStr = "";
                if (i < keys1.Count)
                {
                    keyStr = keys1[i];
                    KeyboardItem item = new KeyboardItem();
                    Canvas.SetLeft(item, left);
                    Canvas.SetTop(item, top);
                    item.SetContent(keyStr);
                    this.cvsRoot.Children.Add(item);
                }
            }

            //第2行
            for (int i = 0; i < 9; i++)
            {
                double left = itemWidth * i + itemWidth * 0.5;
                double top = itemHeight;

                String keyStr = "";
                if (i < keys2.Count)
                {
                    keyStr = keys2[i];
                    KeyboardItem item = new KeyboardItem();
                    Canvas.SetLeft(item, left);
                    Canvas.SetTop(item, top);
                    item.SetContent(keyStr);
                    this.cvsRoot.Children.Add(item);
                }
            }

            //第3行
            for (int i = 0; i < 7; i++)
            {
                double left = itemWidth * i + itemWidth * 1.5;
                double top = itemHeight * 2;

                String keyStr = "";
                if (i < keys3.Count)
                {
                    keyStr = keys3[i];
                    KeyboardItem item = new KeyboardItem();
                    Canvas.SetLeft(item, left);
                    Canvas.SetTop(item, top);
                    item.SetContent(keyStr);
                    this.cvsRoot.Children.Add(item);
                }
            }
        }
    }
}
